package com.example.demo2.controller;

import com.example.demo2.entity.Content;
import com.example.demo2.service.ContentService;
import com.google.gson.Gson;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/msg")
public class ContentController {
    @Autowired
    private ContentService contentService;

    @GetMapping("/getAll") //
    public List getAll(){
        List<Content> list = contentService.findContentAll();
        return list;
    }
    @GetMapping("/getAllJson") //
    public String getAllJson(){
        List<Content> list = contentService.findContentAll();
        Gson gson = new Gson();
        return gson.toJson(list);
    }
    @GetMapping("/getByProCode")
    public String getByProCode(@Param("proCode") Integer proCode){
            List<Content> findByProCode = contentService.findByProCode(proCode);
            Gson gson = new Gson();
              return gson.toJson(findByProCode);
    }
    @GetMapping("/getByProName")
    public String getByProName(@Param("proName") String proName){
            List<Content> findByProName = contentService.findByProName(proName);
            Gson gson = new Gson();
                return gson.toJson(findByProName);
    }
}
